package com.kgc.exception;

import com.kgc.dto.Code;
import com.kgc.dto.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @Author: luo
 * @date: 2024/4/7 9:55
 * @Description:
 * @Version: 1.0
 */
@RestControllerAdvice(basePackages = "com.kgc.controller") //用于标识当前类为REST风格的异常处理器
public class ProjectExceptionAdvice {
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessExceptionException(Exception ex){
        return new Result(null,Code.BUSINESS_ERROR,"业务异常");
    }

    @ExceptionHandler(SystemException.class)
    public Result doSystemException(Exception ex){
        return new Result(null,Code.SYSTEM_ERROR, ex.getMessage());
    }

    //捕获所有异常,返回统一结果
    @ExceptionHandler(Exception.class)
    public Result doOthersException(Exception ex){
        return new Result(null,Code.SYSTEM_ERROR,"其他异常");
    }

}
